import http from './request.js'
//测试地址
http.config.baseUrl = "https://fit.jmlson.com";
//正式环境地址
// http.config.baseUrl = "https://www.nxgyj.com:4443/farm/";

http.interceptor.request = (config) => {
	var token=uni.getStorageSync("token") || 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODIyOTkzMzAsImlhdCI6MTY4MjI5NzUzMCwidXNlcm5hbWUiOiJvc2hjdjQ5eWxsZFpXd1NFV1FEejZoWndET3ZZIn0.2Dm122Qc0WocU-LgtXVXG_A-KXfquU34TmHqP7IxzGA'
	//添加通用参数
	config.header = {
		// "Access-Token": token,
		"mob_ver": "1.0",
		"source": "1",
		// 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
	}
}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	// debugger
	// console.log(response,11111)
	//判断返回状态 执行相应操作
	if (response.statusCode === 200) {
		// if (response.data && response.data.recode==='0000' ) {
		// 	return response.data.result
		// }
		if (response.data && response.data.recode==='0000') {
			return {
				retCode: response.data.recode,
				message: response.data.message||response.data.msg,
				data: response.data.result || response.data.result
			}
		}else{
			uni.$u.toast(response.data.msg||'服务器内部错误');
		}
	}else{
		uni.reLaunch({
			url:'/pages/index/login'
		})
		return {
			retCode: response.statusCode,
			message: '出问题了。。。111',
			data: {}
		}
	}
	
}



function isNumber(obj) {
	return Object.prototype.toString.call(obj) == '[object Number]'
}

export default http;
